# Author: HZT
# Date: 2023/9/6
import time
import page
from base.base import Base
from utils import click_paste_img


class WebCkDd(Base):
    # 获取出卡列表元素
    def sk_jk_get_cklb(self):
        return self.base_find_first(page.web_sk_cklb)

    # 点击出卡中心
    def sk_jk_click_ckzx(self):
        # 定位收卡中心
        switch = self.sk_jk_get_cklb()
        # 判断开关状态
        if switch.get_attribute("class") == "treeview":
            # 列表是未开状态，点击下拉列表
            self.base_find_first(page.web_sk_skzx).click()

    # 点击+订单
    def ck_dd_click_jdd(self):
        self.base_click(page.web_ck_dd_jdd)

    # 点击卡种t-Steam
    def ck_dd_click_tSteam(self):
        self.base_click(page.web_ck_dd_tSteam)

    # 点击卡种t-Sephora
    def ck_dd_click_tSephora(self):
        self.base_click(page.web_ck_dd_tSephora)

    # 输入面额
    def ck_dd_input_me(self, text):
        self.base_input(page.web_ck_dd_me, text)

    # 点击确认发布
    def ck_dd_click_qrfb(self):
        self.base_click(page.web_ck_dd_qrfb)

    # 输入卡密
    def ck_dd_input_km(self, text):
        self.base_input(page.web_ck_dd_km, text)

    # 输入PIN
    def ck_dd_input_pin(self, text):
        self.base_input(page.web_ck_dd_pin, text)

    # 获取上传图片区域的元素
    def ck_dd_get_ddtp(self):
        return self.base_find(page.web_ck_dd_tp)

    # 点击订单
    def ck_dd_click_dd(self):
        self.base_click(page.web_ck_dd_dd)

    # 点击新增
    def ck_dd_click_xz(self):
        self.base_click(page.web_ck_dd_xz)

    # 点击OK
    def ck_dd_click_ok(self):
        self.base_click(page.web_ck_dd_ok)

    # 点击卡种
    def ck_dd_click_kz(self, kz):
        element = page.create_web_ck_dd_kz_selector(kz)
        self.base_click(element)

    # 获取添加卡片元素
    def ck_dd_get_tjkp(self):
        return self.base_find(page.web_ck_dd_tjkp)

    # 组合出卡业务(出count张kz名称的卡,图片路径为filename)
    def ck_dd_ck(self, driver, me, filename, count, kz="t-Steam", km=None, pin=None):
        # 确认页面已进入
        self.ck_dd_get_tjkp()
        self.ck_dd_click_kz(kz)
        self.ck_dd_input_me(me)

        if km:
            self.ck_dd_input_km(km)

        if pin:
            self.ck_dd_input_pin(pin)
        element = self.ck_dd_get_ddtp()
        for _ in range(count):
            click_paste_img(filename, element, driver)

        time.sleep(2)
        self.ck_dd_click_qrfb()
        time.sleep(2)
        self.ck_dd_click_ok()
